

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Most Common Word Sense &mdash; NLP Architect by Intel® AI Lab 0.5.2 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script type="text/javascript" src="_static/jquery.js"></script>
        <script type="text/javascript" src="_static/underscore.js"></script>
        <script type="text/javascript" src="_static/doctools.js"></script>
        <script type="text/javascript" src="_static/language_data.js"></script>
        <script type="text/javascript" src="_static/install.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/nlp_arch_theme.css" type="text/css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono" type="text/css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:100,900" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html">
          

          
            
            <img src="_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
<li class="toctree-l1"><a class="reference internal" href="quick_start.html">Quick start</a></li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorials.html">Jupyter Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="model_zoo.html">Model Zoo</a></li>
</ul>
<p class="caption"><span class="caption-text">NLP/NLU Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="tagging/sequence_tagging.html">Sequence Tagging</a></li>
<li class="toctree-l1"><a class="reference internal" href="sentiment.html">Sentiment Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="bist_parser.html">Dependency Parsing</a></li>
<li class="toctree-l1"><a class="reference internal" href="intent.html">Intent Extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="lm.html">Language Models</a></li>
<li class="toctree-l1"><a class="reference internal" href="information_extraction.html">Information Extraction</a></li>
<li class="toctree-l1"><a class="reference internal" href="transformers.html">Transformers</a></li>
<li class="toctree-l1"><a class="reference internal" href="archived/additional.html">Additional Models</a></li>
</ul>
<p class="caption"><span class="caption-text">Optimized Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="quantized_bert.html">Quantized BERT</a></li>
<li class="toctree-l1"><a class="reference internal" href="transformers_distillation.html">Transformers Distillation</a></li>
<li class="toctree-l1"><a class="reference internal" href="sparse_gnmt.html">Sparse Neural Machine Translation</a></li>
</ul>
<p class="caption"><span class="caption-text">Solutions</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="absa_solution.html">Aspect Based Sentiment Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="term_set_expansion.html">Set Expansion</a></li>
<li class="toctree-l1"><a class="reference internal" href="trend_analysis.html">Trend Analysis</a></li>
</ul>
<p class="caption"><span class="caption-text">For Developers</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="generated_api/nlp_architect_api_index.html">nlp_architect API</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer_guide.html">Developer Guide</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">NLP Architect by Intel® AI Lab</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Most Common Word Sense</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="most-common-word-sense">
<h1>Most Common Word Sense<a class="headerlink" href="#most-common-word-sense" title="Permalink to this headline">¶</a></h1>
<div class="section" id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
<p>The most common word sense algorithm’s goal is to extract the most common sense of a target word.
The input to the algorithm is the target word and the output are the senses of the target word where
each sense is scored according to the most commonly used sense in the language.
note that most of the words in the language have many senses. The sense of a word a consists of the
definition of the word and the inherited hypernyms of the word.</p>
<p>For example: the most common sense of the target_word <strong>burger</strong> is:</p>
<div class="code highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">definition</span><span class="p">:</span> <span class="s2">&quot;a sandwich consisting of a fried cake of minced beef served on a bun, often with other ingredients&quot;</span>
<span class="n">inherited</span> <span class="n">hypernyms</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;sandwich&#39;</span><span class="p">,</span> <span class="s1">&#39;snack_food&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>whereas the least common sense is:</p>
<div class="code highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">definition</span><span class="p">:</span> <span class="s2">&quot;United States jurist appointed chief justice of the United States Supreme Court by Richard Nixon (1907-1995)&quot;</span>
</pre></div>
</div>
<p>Our approach:</p>
<p><strong>Training</strong>: the training inputs a list of target_words where each word is associated with a correct (true example)
or incorrect (false example) sense. The sense consists of the definition and the inherited hypernyms
of the target word in a specific sense.</p>
<p><strong>Inference</strong>: extracts all the possible senses for a specific target_word and scores those senses according
to the most common sense of the target_word. the higher the score the higher the probability of the sense being the most commonly used sense.</p>
<p>In both training and inference a feature vector is constructed as input to the neural network.
The feature vector consists of:</p>
<ul class="simple">
<li>the word embedding distance between the target_word and the inherited hypernyms</li>
<li>2 variations of the word embedding distance between the target_word and the definition</li>
<li>the word embedding of the target_word</li>
<li>the CBOW word embedding of the definition</li>
</ul>
<p>The model above is implemented in the <a class="reference internal" href="generated_api/nlp_architect.models.html#nlp_architect.models.most_common_word_sense.MostCommonWordSense" title="nlp_architect.models.most_common_word_sense.MostCommonWordSense"><code class="xref py py-class docutils literal notranslate"><span class="pre">MostCommonWordSense</span></code></a> class.</p>
</div>
<div class="section" id="dataset">
<h2>Dataset<a class="headerlink" href="#dataset" title="Permalink to this headline">¶</a></h2>
<p>The training module requires a gold standard csv file which is list of target_words where each word
is associated with a CLASS_LABEL - a correct (true example) or an incorrect (false example) sense.
The sense consists of the definition and the inherited hypernyms of the target word in a specific sense.
The user needs to prepare this gold standard csv file in advance.
The file should include the following 4 columns:</p>
<p><a href="#id1"><span class="problematic" id="id2">|</span></a>TARGET_WORD|DEFINITION|SEMANTIC_BRANCH|CLASS_LABEL</p>
<p>where:</p>
<ol class="arabic simple">
<li>TARGET_WORD: the word that you want to get the most common sense of.</li>
<li>DEFINITION: the definition of the word (usually a single sentence) extracted from external resource such as Wordnet or Wikidata</li>
<li>SEMANTIC_BRANCH:  the inherited hypernyms extracted from external resource such as Wordnet or Wikidata</li>
<li>CLASS_LABEL: a binary [0,1] Y value that represent whether the sense (Definition and semantic branch) is the most common sense  of the target word</li>
</ol>
<p>Store the file in the data folder of the project.</p>
</div>
<div class="section" id="running-modalities">
<h2>Running Modalities<a class="headerlink" href="#running-modalities" title="Permalink to this headline">¶</a></h2>
<div class="section" id="dataset-preparation">
<h3>Dataset Preparation<a class="headerlink" href="#dataset-preparation" title="Permalink to this headline">¶</a></h3>
<p>The script prepare_data.py uses the gold standard csv file as described in the requirements section above
using pre-trained Google News Word2vec model <a class="footnote-reference" href="#id6" id="id3">[1]</a> <a class="footnote-reference" href="#id7" id="id4">[2]</a> <a class="footnote-reference" href="#id8" id="id5">[3]</a>. Pre-trained Google News Word2vec model can be download <a class="reference external" href="https://drive.google.com/file/d/0B7XkCwpI5KDYNlNUTTlSS21pQmM/edit?usp=sharing">here</a>.
The terms and conditions of the data set license apply. Intel does not grant any rights to the data files.</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">examples</span><span class="o">/</span><span class="n">most_common_word_sense</span><span class="o">/</span><span class="n">prepare_data</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">gold_standard_file</span> <span class="n">data</span><span class="o">/</span><span class="n">gold_standard</span><span class="o">.</span><span class="n">csv</span>
     <span class="o">--</span><span class="n">word_embedding_model_file</span> <span class="n">pretrained_models</span><span class="o">/</span><span class="n">GoogleNews</span><span class="o">-</span><span class="n">vectors</span><span class="o">-</span><span class="n">negative300</span><span class="o">.</span><span class="n">bin</span>
     <span class="o">--</span><span class="n">training_to_validation_size_ratio</span> <span class="mf">0.8</span>
     <span class="o">--</span><span class="n">data_set_file</span> <span class="n">data</span><span class="o">/</span><span class="n">data_set</span><span class="o">.</span><span class="n">pkl</span>
</pre></div>
</div>
</div>
<div class="section" id="training">
<h3>Training<a class="headerlink" href="#training" title="Permalink to this headline">¶</a></h3>
<p>Trains the MLP classifier (<a class="reference internal" href="generated_api/nlp_architect.models.html#nlp_architect.models.most_common_word_sense.MostCommonWordSense" title="nlp_architect.models.most_common_word_sense.MostCommonWordSense"><code class="xref py py-class docutils literal notranslate"><span class="pre">model</span></code></a>) and evaluate it.</p>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">examples</span><span class="o">/</span><span class="n">most_common_word_sense</span><span class="o">/</span><span class="n">train</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">data_set_file</span> <span class="n">data</span><span class="o">/</span><span class="n">data_set</span><span class="o">.</span><span class="n">pkl</span>
               <span class="o">--</span><span class="n">model</span> <span class="n">data</span><span class="o">/</span><span class="n">wsd_classification_model</span><span class="o">.</span><span class="n">h5</span>
</pre></div>
</div>
</div>
<div class="section" id="inference">
<h3>Inference<a class="headerlink" href="#inference" title="Permalink to this headline">¶</a></h3>
<div class="code python highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">examples</span><span class="o">/</span><span class="n">most_common_word_sense</span><span class="o">/</span><span class="n">inference</span><span class="o">.</span><span class="n">py</span> <span class="o">--</span><span class="n">max_num_of_senses_to_search</span> <span class="mi">3</span>
     <span class="o">--</span><span class="n">input_inference_examples_file</span> <span class="n">data</span><span class="o">/</span><span class="n">input_inference_examples</span><span class="o">.</span><span class="n">csv</span>
     <span class="o">--</span><span class="n">word_embedding_model_file</span> <span class="n">pretrained_models</span><span class="o">/</span><span class="n">GoogleNews</span><span class="o">-</span><span class="n">vectors</span><span class="o">-</span><span class="n">negative300</span><span class="o">.</span><span class="n">bin</span>
     <span class="o">--</span><span class="n">model</span> <span class="n">data</span><span class="o">/</span><span class="n">wsd_classification_model</span><span class="o">.</span><span class="n">h5</span>
</pre></div>
</div>
<p>Where the <code class="docutils literal notranslate"><span class="pre">max_num_of_senses_to_search</span></code> is the maximum number of senses that are checked per target word (default =3)
and <code class="docutils literal notranslate"><span class="pre">input_inference_examples_file</span></code> is a csv file containing the input inference data. This file includes
a single column wherein each entry in this column is a different target word</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The results are printed to the terminal using different colors therefore using a white terminal background is best to view the results</p>
</div>
<table class="docutils footnote" frame="void" id="id6" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[1]</a></td><td>Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient Estimation of Word Representations in Vector Space. In Proceedings of Workshop at ICLR, 2013.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id7" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id4">[2]</a></td><td>Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, and Jeffrey Dean. Distributed Representations of Words and Phrases and their Compositionality. In Proceedings of NIPS, 2013.</td></tr>
</tbody>
</table>
<table class="docutils footnote" frame="void" id="id8" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[3]</a></td><td>Tomas Mikolov, Wen-tau Yih, and Geoffrey Zweig. Linguistic Regularities in Continuous Space Word Representations. In Proceedings of NAACL HLT, 2013.</td></tr>
</tbody>
</table>
</div>
</div>
</div>


           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>